<template>
  <div class="app-container">
    <el-row>
      <el-col :span="24">
        <div class="h_top">
          <div class="bread_title">
            <span>新增故障报修工单</span>
          </div>
          <div class="buttonBox">
            <el-button type="primary" icon="el-icon-back" size="mini" @click="goBack">返回</el-button>
          </div>
          <div class="save_button">
            <div class="buttonBox">
              <el-button type="primary" icon="el-icon-document-checked" size="mini" @click="save">保存</el-button>
            </div>
          </div>
        </div>
      </el-col>
    </el-row>
    <div>
      <el-row>
        <el-col :span="24">
          <el-form ref="form" :model="data" :inline="true" :rules="formRules">
            <el-input v-model="data.id" type="hidden" />
            <el-row :gutter="10">
              <el-col :span="4">
                <el-form-item prop="coding">
                  <div>编号</div>
                  <el-input v-model="data.coding" size="mini" />
                </el-form-item>
              </el-col>
              <el-col :span="4">
                <el-form-item prop="name">
                  <div>名称</div>
                  <el-input v-model="data.name" size="mini" />
                </el-form-item>
              </el-col>
              <el-col :span="4">
                <el-form-item prop="apply_id">
                  <div>报修申请</div>
                  <v-select v-model="data.apply_id" action="applyList" :query="{status: 0}" />
                </el-form-item>
              </el-col>
              <el-col :span="4">
                <el-form-item prop="arrange_date">
                  <div>安排时间</div>
                  <el-date-picker v-model="data.arrange_date" type="datetime" value-format="yyyy-MM-dd HH:mm:ss" size="mini" />
                </el-form-item>
              </el-col>
              <el-col :span="4">
                <el-form-item prop="target_date">
                  <div>目标时间</div>
                  <el-date-picker v-model="data.target_date" type="datetime" value-format="yyyy-MM-dd HH:mm:ss" size="mini" />
                </el-form-item>
              </el-col>
              <el-col :span="4">
                <el-form-item prop="admin_id">
                  <div>负责人</div>
                  <v-select v-model="data.admin_id" />
                </el-form-item>
              </el-col>
              <el-col :span="4">
                <el-form-item prop="profession">
                  <div>专业</div>
                  <el-select v-model="data.profession" placeholder="请选择" size="mini">
                    <el-option v-for="(item, index) in profession" :key="index" :label="item" :value="index" />
                  </el-select>
                </el-form-item>
              </el-col>
              <el-col :span="4">
                <el-form-item prop="sort">
                  <div>排序</div>
                  <el-input v-model="data.sort" size="mini" />
                </el-form-item>
              </el-col>
            </el-row>
          </el-form>
          <el-tabs>
            <el-tab-pane label="描述">
              <el-row>
                <el-col :span="24">
                  <Tinymce id="content" v-model="data.content" />
                </el-col>
              </el-row>
            </el-tab-pane>
          </el-tabs>
        </el-col>
      </el-row>
    </div>
  </div>
</template>
<script>
import API from '@/api/maintain/cm'
import { profession } from '@/utils/options'
import Tinymce from '@/components/Tinymce/index'
import VSelect from '@/components/select'
export default {
  inject: ['addOne', 'goUrl'],
  components: {
    Tinymce,
    VSelect
  },
  data() {
    return {
      data: {
        coding: '',
        name: '',
        arrange_date: '',
        target_date: '',
        sort: 100
      },
      profession,
      formRules: {
        coding: [
          {
            required: true,
            message: '请输入编号',
            trigger: 'blur'
          }
        ],
        name: [
          {
            required: true,
            message: '请输入分类名称',
            trigger: 'blur'
          }
        ],
        apply_id: [
          {
            required: true,
            message: '请选择报修申请',
            trigger: 'change'
          }
        ],
        arrange_date: [
          {
            required: true,
            message: '请选择安排时间',
            trigger: 'change'
          }
        ],
        target_date: [
          {
            required: true,
            message: '请选择目标时间',
            trigger: 'change'
          }
        ],
        admin_id: [
          {
            required: true,
            message: '请选择负责人',
            trigger: 'change'
          }
        ],
        profession: [
          {
            required: true,
            message: '请选择专业',
            trigger: 'change'
          }
        ],
        sort: [
          {
            required: true,
            message: '请输入排序',
            trigger: 'blur'
          }
        ]
      }
    }
  },
  created() {},
  methods: {
    save() {
      const thisData = this.data
      const thisForm = this.$refs.form
      this.addOne(API, thisData, thisForm)
    },
    goBack() {
      this.goUrl('/maintain/cm')
    }
  }
}
</script>
